#ifndef INDEXCALCULATOR_H
#define INDEXCALCULATOR_H

#include "CircularBuffer.h"

template <typename NewDataType, typename ResultType>
class IndexCalculator
{
protected:
    CircularBuffer<NewDataType> data;
    ResultType result;
    int period;
    int data_count;

public:
    explicit IndexCalculator(int period) : data(period), result(), period(period), data_count(0) {}

    ResultType update(const NewDataType &new_data)
    {
        data_count++;
        calculate(new_data);
        data.push_back(new_data);
        return result;
    }

    virtual void calculate(const NewDataType &new_data) = 0;

    virtual void reset()
    {
        data.clear();
        result = ResultType();
        data_count = 0;
    }
};

#endif // INDEXCALCULATOR_H